#!/bin/sh
PROGRAM=$(cat  server/CMakeLists.txt  | grep "add_executable" |awk -F '(' '{print $2}'| awk -F ' ' '{print $1}'| sed 's/\"//g')
MAIN_VERSION=$(cat server/versiondesc.h | grep -E '{*},'| tail -n 1 | awk -F ',' '{print $(NF-3)}' |tr -cd "[0-9]")
MINOR_VERSION=$(cat server/versiondesc.h | grep -E '{*},'| tail -n 1 | awk -F ',' '{print $(NF-2)}' |tr -cd "[0-9]")
PATCH_VERSION=$(cat server/versiondesc.h | grep -E '{*},'| tail -n 1 | awk -F ',' '{print $(NF-1)}' |tr -cd "[0-9]")
GIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
STATE=$( cat CMakeLists.txt  | grep "CMAKE_BUILD_TYPE"| grep "set"|awk  -F '"' '{print $2}')


echo "版本号:   ${PROGRAM}V${MAIN_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${GIT_BRANCH_NAME}-${STATE}"



CurrentDir=`basename $PWD`
DATE=$(date +%Y-%m-%d)

DEV_TARGETS=$(find .  -name "*.[h|c]" -o -name "*.go"  -o -name "*.cpp" -o -name "*.hpp" -o -name "package.json " | grep -v jsoncpp| grep -v build | grep -v Android)
 
DEV_TARGETFILENAME=${PROGRAM}_${DATE}_V${MAIN_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${GIT_BRANCH_NAME}-${STATE}_devel.tar.gz
if  [  -f   ${DEV_TARGETFILENAME} ];then
    rm  -rf ${DEV_TARGETFILENAME}
fi    
tar  -zcvf  ${DEV_TARGETFILENAME}   ${DEV_TARGETS}
echo "tarball:${DEV_TARGETFILENAME}!"

REALEASE_TARGETS="
	    conf/config.ini 
	    CMakeLists.txt
	    ReleaseNotes.txt
	    release/linux/${STATE}/${PROGRAM}
"
REALEASE_TARGETFILENAME=${PROGRAM}_${DATE}_V${MAIN_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.${GIT_BRANCH_NAME}-${STATE}.tar.gz
if  [  -f   ${REALEASE_TARGETFILENAME} ];then
    rm  -rf ${REALEASE_TARGETFILENAME}
fi 
tar  -zcvf  ${REALEASE_TARGETFILENAME}   ${REALEASE_TARGETS}
echo "tarball:${REALEASE_TARGETFILENAME}!"


